<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>用户组权限管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="static/layuiadmin/layui/css/admin.css" media="all">

</head>
<body>
<!--templates/table/yhzqxkz-->
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header card-title">用户组权限管理</div>
        <div class="layui-card-body">
          <div id="treegrid"></div>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="static/layui/layui.all.js"></script>
<script th:inline="none">
  var $ = layui.$;
  var treeData = null;
  $.ajax({
    url: "/selectyhzqxgl",
    type: "POST",
    contentType: "application/json",
    async: false,
    success: function(data) {
      var obj = JSON.parse(data);
      treeData = obj.data;
    }
  })
  layui.use(['tree', 'util'], function(){
    var tree = layui.tree
    ,layer = layui.layer
    ,checkCallback = false
    ,util = layui.util;
    layer.load(1, {time: 1000, end: () => checkCallback = true});
    //渲染
      tree.render({
      elem: '#treegrid'  //绑定元素
      ,showCheckbox:true
      ,id: 'tree1'
      ,showLine:false
      ,data: treeData
      ,oncheck:function(obj){
        if (!checkCallback)
          return ;
          console.log(obj.data.id); //得到当前点击的节点数据
          console.log(obj.checked); //得到当前节点的展开状态：open、close、normal
          up(obj.data.id,obj.checked);
          // console.log(obj.elem); //得到当前节点元素
        }
    });
  });
function up(id,checked) {
  layui.use(['tree', 'util'], function(){
      var layer = layui.layer;
  $.ajax({
    url: "/upyhzqxgl",
    type: "POST",
    async: false,
    data:{"id":id,"checked":checked},
    success: function(data) {
      layer.msg('更改成功',{icon:1});
    },
    false:function () {
      layer.msg('更改失败',{icon:2});
    }
  });
  });
}

</script>
</body>
</html>